package com.action.h5;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bean.ResponseBean;
import com.pojo.News;
import com.pojo.Newtype;
import com.pojo.Zixun;
import com.service.NewsService;
import com.service.NewtypeService;
import com.service.ZixunService;
import com.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * h5新闻查询操作
 * @author Liao
 */
@RestController
@RequestMapping("/h5")
public class Xinwenh5Action {
    @Autowired
    NewtypeService newtypeService;
    @Autowired
    NewsService newsService;

    /**
     * 查询所有启用的新闻类型
     * @return
     */
    @RequestMapping("/getnewstype")
    public ResponseBean getnewstype(){
        List list = newtypeService.list(new QueryWrapper<Newtype>().eq("status",1));
        if(list.size()>0){
            return  new ResponseBean(200,"成功",list);
        }
        else{
            return ResponseBean.error("没有数据");
        }
    }
    /**
     * 分页查询不同新闻类型的的新闻列表
     * @return
     */
    @RequestMapping("/newspage")
    public ResponseBean newspage(int page,int limit,String newstype){
        IPage iPage = newsService.getNewsPage(page,limit,newstype);
        return new ResponseBean(200,iPage.getTotal(),"成功",iPage.getRecords());
    }
    /**
     * 查询不同新闻类型下的热门新闻,只显示前3个
     * @return
     */
    @RequestMapping("/hotnews")
    public ResponseBean hotNews(String newstype){
        if(StringUtil.isNull(newstype)){
            return ResponseBean.error("查询的分类不能为空");
        }
        List list = newsService.getHotNews(newstype);
        return new ResponseBean(200,list.size(),"成功",list);
    }
    /**
     * 查询不同新闻类型下的轮播新闻,只显示前5个
     * @return
     */
    @RequestMapping("/lunbonews")
    public ResponseBean lunboNews(String newstype){
        if(StringUtil.isNull(newstype)){
            return ResponseBean.error("查询的分类不能为空");
        }
        List list = newsService.lunboNews(newstype);
        return new ResponseBean(200,list.size(),"成功",list);
    }
    /**
     * 查询新闻的详情
     * @return
     */
    @RequestMapping("/newsdetail")
    public ResponseBean newsDetail(String nsid){
        if(StringUtil.isNull(nsid)){
            return ResponseBean.error("新闻编号不能为空");
        }
        News xinwen = newsService.getById(nsid);
        return new ResponseBean(200,1,"成功",xinwen);
    }
}
